package com.siruier.boss.ui.activity.mall

import android.view.View
import androidx.core.view.isVisible
import com.siruier.boss.api.core.launchUI
import com.siruier.boss.bean.ConfirmOrderGoodsBean
import com.siruier.boss.bean.MallGoodsBean
import com.siruier.boss.common.formatPrice
import com.siruier.boss.common.formatPriceRmb
import com.siruier.boss.databinding.ActivityOrderPaySuccessBinding
import com.siruier.boss.ui.activity.main.MainActivity
import com.siruier.boss.ui.api.ApiObserver
import com.siruier.boss.ui.base.BaseActivity
import com.siruier.boss.ui.ext.startActivityExt
import com.siruier.boss.ui.helper.InjectBundle
import com.siruier.boss.ui.helper.ShareHelper
import java.math.BigDecimal

class OrderPaySuccessActivity : BaseActivity<ActivityOrderPaySuccessBinding>() {
    private val mOrderSn: String by InjectBundle()
    private val picUrl: String by InjectBundle()
    private val passOn: Boolean by InjectBundle { false }
    private val mOrderPrice: BigDecimal by InjectBundle()
    private val mGoods: MallGoodsBean by InjectBundle()
    private val type: Int by InjectBundle()
    override fun initView() {
        if (type !in 2..3) {
            bindViewClick(vb.buttonSend)
        }
        bindViewClick(vb.buttonClose, vb.buttonDetail)
        vb.tvPayMoney.text = mOrderPrice.formatPriceRmb()
        vb.buttonSend.isVisible = passOn && type !in 2..3
    }

    override fun onClick(v: View?) {
        when (v) {
            vb.buttonSend -> {
                ShareHelper.orderTransfer(
                    mThis, vb.viewOrderTransfer, mGoods.picUrl, mGoods.name, mGoods.priceDesc,
                    mGoods.marketPrice.formatPrice(), mOrderSn
                )
            }
            vb.buttonClose -> {
                startActivityExt<MainActivity>()
            }
            vb.buttonDetail -> {
                startActivityExt<UserOrderDetailsActivity> {
                    putExtra("mOrderSn", mOrderSn)
                }
                finish()
            }
        }
    }
}